package com.five.community.config;

import com.five.community.contant.AppContants;
import com.five.community.intercepetor.ActivityInterceptor;
import com.five.community.intercepetor.AdminIntercepetor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppConfig implements WebMvcConfigurer {

    @Autowired
    private ActivityInterceptor activityInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:" + AppContants.FILE_PATH);

    }
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //添加拦截器
        InterceptorRegistration registration = registry.addInterceptor(new AdminIntercepetor());
        //设置拦截画面路径
        registration.addPathPatterns("/indexUi");
        //活动管理权限拦截器
        registry.addInterceptor(activityInterceptor).addPathPatterns("/activity/limit/*");
        //信箱管理权限拦截器
        registry.addInterceptor(activityInterceptor).addPathPatterns("/mailbox/limit/*");
        //投诉管理权限拦截器
        registry.addInterceptor(activityInterceptor).addPathPatterns("/complaint/limit/*");
        //报修管理权限拦截器
        registry.addInterceptor(activityInterceptor).addPathPatterns("/repair/limit/*");
    }





}